package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLich;
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLichService;
import com.lb.jwitter.service.TblQLDTTXAHocVien;
import com.lb.jwitter.service.TblQLDTTXAHocVienService;

import com.lb.jwitter.service.TblQLDTTXADMDanToc;
import com.lb.jwitter.service.TblQLDTTXADMDanTocService;

import com.lb.jwitter.service.TblQLDTTXADMTonGiao;
import com.lb.jwitter.service.TblQLDTTXADMTonGiaoService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVientblQLDTTXAHocVienPhieuLyLichUpdateAction{
    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
 }

    public int getHocVienId() {
       return hocVienId;
 }

    private TblQLDTTXAHocVienService tblQLDTTXAHocVienService; 

    private String dienThoai; 
    public void setDienThoai(String dienThoai) {
       this.dienThoai = dienThoai;
 }

    public String getDienThoai() {
       return dienThoai;
 }

    private String ngaySinh; 
    public void setNgaySinh(String ngaySinh) {
       this.ngaySinh = ngaySinh;
 }

    public String getNgaySinh() {
       return ngaySinh;
 }

    private String noiSinh; 
    public void setNoiSinh(String noiSinh) {
       this.noiSinh = noiSinh;
 }

    public String getNoiSinh() {
       return noiSinh;
 }

    private int gioiTinh; 
    public void setGioiTinh(int gioiTinh) {
       this.gioiTinh = gioiTinh;
 }

    public int getGioiTinh() {
       return gioiTinh;
 }

    private String thuongTru; 
    public void setThuongTru(String thuongTru) {
       this.thuongTru = thuongTru;
 }

    public String getThuongTru() {
       return thuongTru;
 }

    private String choOHiennay; 
    public void setChoOHiennay(String choOHiennay) {
       this.choOHiennay = choOHiennay;
 }

    public String getChoOHiennay() {
       return choOHiennay;
 }

    private int danTocId; 
    public void setDanTocId(int danTocId) {
       this.danTocId = danTocId;
 }

    public int getDanTocId() {
       return danTocId;
 }

    private TblQLDTTXADMDanTocService tblQLDTTXADMDanTocService; 

    private int tonGiaoId; 
    public void setTonGiaoId(int tonGiaoId) {
       this.tonGiaoId = tonGiaoId;
 }

    public int getTonGiaoId() {
       return tonGiaoId;
 }

    private TblQLDTTXADMTonGiaoService tblQLDTTXADMTonGiaoService; 

    private String thongtinDoan; 
    public void setThongtinDoan(String thongtinDoan) {
       this.thongtinDoan = thongtinDoan;
 }

    public String getThongtinDoan() {
       return thongtinDoan;
 }

    private String thongtinDang; 
    public void setThongtinDang(String thongtinDang) {
       this.thongtinDang = thongtinDang;
 }

    public String getThongtinDang() {
       return thongtinDang;
 }

    private String thongtinQD; 
    public void setThongtinQD(String thongtinQD) {
       this.thongtinQD = thongtinQD;
 }

    public String getThongtinQD() {
       return thongtinQD;
 }

    private String hinhAnh; 
    public void setHinhAnh(String hinhAnh) {
       this.hinhAnh = hinhAnh;
 }

    public String getHinhAnh() {
       return hinhAnh;
 }

    private TblQLDTTXAHocVienPhieuLyLich tblQLDTTXAHocVienPhieuLyLich; 
    public void setTblQLDTTXAHocVienPhieuLyLich (TblQLDTTXAHocVienPhieuLyLich tblQLDTTXAHocVienPhieuLyLich) {
        this.tblQLDTTXAHocVienPhieuLyLich = tblQLDTTXAHocVienPhieuLyLich;
 }

    private TblQLDTTXAHocVienPhieuLyLichService tblQLDTTXAHocVienPhieuLyLichService; 

	private int preUpdate(Message msg, TblQLDTTXAHocVienPhieuLyLich obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAHocVienPhieuLyLich obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_PhieuLyLich", "sua")){ 
        return "noprivilege"; 
    }
        tblQLDTTXAHocVienPhieuLyLichService = (TblQLDTTXAHocVienPhieuLyLichService) context.getBean("tbl_QLDTTXA_HocVien_PhieuLyLichClient"); 
        tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient"); 

        tblQLDTTXADMDanTocService = (TblQLDTTXADMDanTocService) context.getBean("tbl_QLDTTXA_DM_DanTocClient"); 

        tblQLDTTXADMTonGiaoService = (TblQLDTTXADMTonGiaoService) context.getBean("tbl_QLDTTXA_DM_TonGiaoClient"); 

        msg = new Message(); 
        tblQLDTTXAHocVienPhieuLyLich = tblQLDTTXAHocVienPhieuLyLichService.gettblQLDTTXAHocVienPhieuLyLich(new Long(id)); 
        tblQLDTTXAHocVienPhieuLyLich.setHocVienId(tblQLDTTXAHocVienService.gettblQLDTTXAHocVien(new Long(hocVienId))); 
        tblQLDTTXAHocVienPhieuLyLich.setDienThoai(dienThoai); 
       DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
       Date dd = df.parse(ngaySinh); 
       GregorianCalendar c = new GregorianCalendar(); 
       c.setTime(dd);
       XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
        tblQLDTTXAHocVienPhieuLyLich.setNgaySinh(d); 
        tblQLDTTXAHocVienPhieuLyLich.setNoiSinh(noiSinh); 
        if(gioiTinh == 1){ 
           tblQLDTTXAHocVienPhieuLyLich.setGioiTinh(true); 
       } else { 
           tblQLDTTXAHocVienPhieuLyLich.setGioiTinh(false); 
       } 
        tblQLDTTXAHocVienPhieuLyLich.setThuongTru(thuongTru); 
        tblQLDTTXAHocVienPhieuLyLich.setChoOHiennay(choOHiennay); 
        tblQLDTTXAHocVienPhieuLyLich.setDanTocId(tblQLDTTXADMDanTocService.gettblQLDTTXADMDanToc(new Long(danTocId))); 
        tblQLDTTXAHocVienPhieuLyLich.setTonGiaoId(tblQLDTTXADMTonGiaoService.gettblQLDTTXADMTonGiao(new Long(tonGiaoId))); 
        tblQLDTTXAHocVienPhieuLyLich.setThongtinDoan(thongtinDoan); 
        tblQLDTTXAHocVienPhieuLyLich.setThongtinDang(thongtinDang); 
        tblQLDTTXAHocVienPhieuLyLich.setThongtinQD(thongtinQD); 
        tblQLDTTXAHocVienPhieuLyLich.setHinhAnh(hinhAnh); 
        preUpdate(msg,tblQLDTTXAHocVienPhieuLyLich); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAHocVienPhieuLyLichService.updatetblQLDTTXAHocVienPhieuLyLich(tblQLDTTXAHocVienPhieuLyLich); 
           postUpdate(msg, tblQLDTTXAHocVienPhieuLyLich); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_HocVien_PhieuLyLich Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
